<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>DStation后台管理</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- Bootstrap Core CSS -->
    <link th:href="@{/boostrapTemplatResources/vendor/bootstrap/css/bootstrap.min.css}" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link th:href="@{/boostrapTemplatResources/vendor/metisMenu/metisMenu.min.css}" rel="stylesheet">

    <!-- Custom CSS -->
    <link th:href="@{/boostrapTemplatResources/dist/css/sb-admin-2.css}" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link th:href="@{/boostrapTemplatResources/vendor/morrisjs/morris.css}" rel="stylesheet">

    <!-- Custom Fonts -->
    <link th:href="@{/boostrapTemplatResources/vendor/font-awesome/css/font-awesome.min.css}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="/webjars/jquery/3.1.1/jquery.js"></script>
    <script src="/js/sweetAlert.js"></script>
</head>

<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
    <div th:include="admin/header::header"></div>
    <div th:include="admin/sidebar::sidebar"></div>
</nav>

<!--显示主体部分 -->
<div id="wrapper">
    <!-- 主界面显示D站介绍信息 -->
    <div id="page-wrapper">
        <!-- 存放视频的分类信息的table -->
        <br>
        <table id="table"  class="table table-bordered">
            <thead>
            <tr>
                <th>动态编号</th>
                <th hidden>用户编号</th>
                <th>发布者</th>
                <th>内容</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="dynamicInfo : ${dynamicInfoIPage.records}">
                <td th:text="${dynamicInfo.dynamicId}"></td>
                <td th:text="${dynamicInfo.userId}" hidden></td>
                <td th:text="${dynamicInfo.userName}"></td>
                <td style="text-align:center;vertical-align:middle;">
                    <textarea th:text="${dynamicInfo.dynamicContent}" style="width: 330px;">
                    </textarea>
                </td>
                <td th:text="${dynamicInfo.createDate}">
                </td>
                <td>
                    <a class="btn btn-sm btn-success" th:onclick="'intelligenceExamine('+${dynamicInfo.dynamicId}+')'">智能审核</a>
                    <a class="btn btn-sm btn-success" th:onclick="'access('+${dynamicInfo.dynamicId}+')'">通过</a>
                    <a class="btn btn-sm btn-danger" th:onclick="'reject('+${dynamicInfo.dynamicId}+')'">拒绝</a>
                </td>
            </tr>
            </tbody>
        </table>
        <div >
            <div class="center " style="padding-left: 45%;!important;">
                <a th:href="@{/dynamicExamine/dynamicExaminePage(page=${dynamicInfoIPage.current}-1)}"
                   th:class="${dynamicInfoIPage.current == 1}? 'disabled btn btn-primary btn-xs':'btn btn-primary btn-xs'"
                   class="btn btn-primary btn-xs" >上一页</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;
                <a th:href="@{/dynamicExamine/dynamicExaminePage(page=${dynamicInfoIPage.current}+1)}"
                   th:class="${dynamicInfoIPage.current == dynamicInfoIPage.pages?'disabled btn btn-primary btn-xs':'btn btn-primary btn-xs'}" class="btn btn-primary btn-xs">下一页</a>
            </div>
        </div>
        <div>
            <div class="center " style="padding-left: 45%;!important;">
                当前第 [[${dynamicInfoIPage.current}]]页,共 [[${dynamicInfoIPage.pages}]] 页.一共 [[${dynamicInfoIPage.total}]] 条记录
            </div>
        </div>
    </div>
    <!-- /#page-wrapper -->
</div>


<script th:src="@{/boostrapTemplatResources/js/html5shiv.js}"></script>
<script th:src="@{/boostrapTemplatResources/js/respond.min.js}"></script>

<!-- jQuery -->
<script th:src="@{/boostrapTemplatResources/vendor/jquery/jquery.min.js}"></script>

<!-- Bootstrap Core JavaScript -->
<script th:src="@{/boostrapTemplatResources/vendor/bootstrap/js/bootstrap.min.js}"></script>

<!-- Metis Menu Plugin JavaScript -->
<script th:src="@{/boostrapTemplatResources/vendor/metisMenu/metisMenu.min.js}"></script>

<!-- Morris Charts JavaScript -->
<script th:src="@{/boostrapTemplatResources/vendor/raphael/raphael.min.js}"></script>
<script th:src="@{/boostrapTemplatResources/vendor/morrisjs/morris.min.js}"></script>
<script th:src="@{/boostrapTemplatResources/data/morris-data.js}"></script>

<!-- Custom Theme JavaScript -->
<script th:src="@{/boostrapTemplatResources/dist/js/sb-admin-2.js}"></script>

<script type="text/javascript">

    var intervalFlag = null;

    /**
     * 通过
     * @param id
     */
    function access(id) {
        swal({
            title: "确认弹框",
            text: "确定要通过吗?",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((flag) => {
            if(flag) {
                $.ajax(
                    {
                        type: "POST",
                        url: "/dynamicExamine/accessExamine",
                        async: false,
                        cache: true,
                        data: {
                            "id": id,
                            "isPass":1
                        },
                        success: function (data) {
                            if(data["res"] == true) {
                                swal("审核已通过!", {
                                    buttons: false,
                                    timer: 1000
                                });
                                window.location.reload();
                            } else {
                                swal("Error", "审核通过失败", "error");
                            }
                        },
                        error: function (data) {
                            swal("Error", "网络错误，请联系管理员！", "error");
                        }
                    }
                );
            }
        } );
    }


    /**
     * 智能审核
     * @param id
     */
    function intelligenceExamine(id) {
        if(intervalFlag != null) {
            swal("Warning", "有任务正在处理！", "warning");
            return ;
        }
        swal({
            title: "确认弹框",
            text: "已提交至智能审核，请及时查看结果！",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((flag) => {
            $.ajax(
            {
                type: "POST",
                url: "/dynamicExamine/intelligenceExamine",
                async: false,    //设置为同步请求
                cache: true,
                data: {
                    "dynamicId": id
                },
                success: function (data) {  //提交视频成功
                    var taskId = data["taskId"]; //任务id
                    var dataId = data["dataId"];    //dataID
                    intervalFlag = setInterval(
                        function(){
                            referExamineRes(id, taskId,dataId);
                        }
                        ,10000);
                    swal({
                        title: "正在审核中, 请稍后.....",
                        showConfirmButton: false,
                        showCancelButton: false,
                        buttons: false
                    });
                },
                error: function (data) {
                    swal("Error", "网络错误，请联系管理员！", "error");
                }
            }
        );
    } );
    }

    function referExamineRes(id ,taskId,dataId) {
        $.ajax(
            {
                type: "POST",
                url: "/dynamicExamine/referExamineResByTaskId",
                async: true,    //异步请求
                cache: true,
                data: {
                    "dynamicId": id,
                    "taskId":taskId,
                    "dataId":dataId
                },
                success: function (data) {  //提交视频成功
                    var code = data["code"];
                    if(code == 200) {   //说明后台已经处理成功
                        window.clearInterval(intervalFlag); //停止请求
                        intervalFlag = null;
                        swal("任务ID为" + taskId + "的动态审核完成，请在阿里云后台查看结果！", {
                            buttons: false,
                            timer: 1500,
                            icon: "success"
                        });
                        //2秒后刷新页面，足够显示swal()的信息
                        setTimeout(function(){window.location.reload(); },1100);
                    } else {
                        window.clearInterval(intervalFlag); //停止请求
                        intervalFlag = null;
                        swal("审核失败，请在后台查看原因！", {
                            buttons: false,
                            timer: 1500,
                            icon: "warning"
                        });
                        //2秒后刷新页面，足够显示swal()的信息
                        setTimeout(function(){window.location.reload(); },1100);
                    }
                },
                error: function (data) {
                    swal("Error", "网络错误，请联系管理员！", "error");
                }
            }
        );
    }

    function reject(id) {
        swal({
            title: "确认弹框",
            text: "确定要拒绝吗?",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((flag) => {
            if(flag) {
                $.ajax(
                    {
                        type: "POST",
                        url: "/dynamicExamine/accessExamine",
                        async: false,
                        cache: true,
                        data: {
                            "id": id,
                            "isPass":0
                        },
                        success: function (data) {
                            if(data["res"] == true) {
                                swal("审核已拒绝!", {
                                    buttons: false,
                                    timer: 1000
                                });
                                window.location.reload();
                            } else {
                                swal("Error", "审核通过失败", "error");
                            }
                        },
                        error: function (data) {
                            swal("Error", "网络错误，请联系管理员！", "error");
                        }
                    }
                );
            }
        } );
    }
</script>
</body>

</html>









